import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class main {
    public static void main(String[] args){
//        LoanCalculator loanCalculator = new LoanCalculator(100,360,0.049);
//        loanCalculator.avgCaption();
//        loanCalculator.avgInterest();
//        loanCalculator.print(1);
//        loanCalculator.print(2);
        JFrame window = new JFrame();
        window.setLayout(new FlowLayout());

        window.setSize(600,500);
        window.setTitle("贷款计算器");

        JLabel labelAmount = new JLabel("贷款总额:") ;
        JLabel labelPeriod = new JLabel("贷款期数:") ;
        JLabel labelInterest = new JLabel("贷款年利率:") ;

        JTextField textAmount = new JTextField();
        JTextField textPeriod = new JTextField();
        JTextField textInterest = new JTextField();

        textAmount.setColumns(10);
        textPeriod.setColumns(10);
        textInterest.setColumns(10);

        JRadioButton radioAvgCaption = new JRadioButton("等额本金");
        JRadioButton radioAvgInterest = new JRadioButton("等额本息");

        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(radioAvgCaption);
        buttonGroup.add(radioAvgInterest);

        JLabel labelTotalInterest = new JLabel("总利息");
        JTextField TextTotalInterest = new JTextField();
        TextTotalInterest.setColumns(20);

        JButton button = new JButton();
        button.setLabel("计算");
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //1.读取用户输入
                int amount = Integer.parseInt(textAmount.getText()) ;
                int period = Integer.parseInt(textPeriod.getText()) ;
                double yearinterest = Double.parseDouble(textInterest.getText()) ;
                //2.计算
                LoanCalculator loanCalculator = new LoanCalculator(amount,period,yearinterest);
                double result = 0.0;
                if (radioAvgCaption.isSelected()) {
                    result = loanCalculator.avgInterest();
                }else {
                    result = loanCalculator.avgInterest();
                }
                //3.输出
                textTota

            }
        });

        window.add(labelAmount);
        window.add(textAmount);
        window.add(labelInterest);
        window.add(textPeriod);
        window.add(labelPeriod);
        window.add(textInterest);
        window.add(radioAvgCaption);
        window.add(radioAvgInterest);
        window.add(labelTotalInterest);
        window.add(TextTotalInterest);
        window.add(button);

        window.setVisible(true);
    }
}
